home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / pupi-button.scm < prev    next >
Encoding:
Text File  |  2005-06-30  |  6.3 KB  |  208 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Round Button --- create a round beveled Web button.
  4. ; Copyright (C) 1998 Federico Mena Quintero & Arturo Espinosa Aldama
  5. ; federico@nuclecu.unam.mx arturo@nuclecu.unam.mx
  6. ; ************************************************************************
  7. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  8. ; For use with GIMP 1.1.
  9. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  10. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  11. ; ************************************************************************
  12. ; This program is free software; you can redistribute it and/or modify
  13. ; it under the terms of the GNU General Public License as published by
  14. ; the Free Software Foundation; either version 2 of the License, or
  15. ; (at your option) any later version.
  16. ; This program is distributed in the hope that it will be useful,
  17. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ; GNU General Public License for more details.
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with this program; if not, write to the Free Software
  22. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. (define (text-width extents)
  25.   (car extents))
  26.  
  27. (define (text-height extents)
  28.   (cadr extents))
  29.  
  30. (define (text-ascent extents)
  31.   (caddr extents))
  32.  
  33. (define (text-descent extents)
  34.   (cadr (cddr extents)))
  35.  
  36. (define (round-select img
  37.               x
  38.               y
  39.               width
  40.               height
  41.               ratio)
  42.   (let* ((diameter (* ratio height)))
  43.     (gimp-ellipse-select img x y diameter height CHANNEL-OP-ADD FALSE 0 0)
  44.     (gimp-ellipse-select img (+ x (- width diameter)) y
  45.              diameter height CHANNEL-OP-ADD FALSE 0 0)
  46.     (gimp-rect-select img (+ x (/ diameter 2)) y
  47.               (- width diameter) height CHANNEL-OP-ADD FALSE 0)))
  48.  
  49. (define (script-fu-round-button text
  50.                 size
  51.                 font
  52.                 ul-color
  53.                 lr-color
  54.                 text-color
  55.                 ul-color-high
  56.                 lr-color-high
  57.                 hlight-color
  58.                 xpadding
  59.                 ypadding
  60.                 bevel
  61.                 ratio
  62.                 notpressed
  63.                 notpressed-active
  64.                 pressed)
  65.  
  66.   (cond ((eqv? notpressed TRUE)
  67.      (do-pupibutton text size font ul-color lr-color
  68.             text-color xpadding ypadding bevel ratio 0)))
  69.   (cond ((eqv? notpressed-active TRUE)
  70.      (do-pupibutton text size font ul-color-high lr-color-high
  71.             hlight-color xpadding ypadding bevel ratio 0)))
  72.   (cond ((eqv? pressed TRUE)
  73.      (do-pupibutton text size font ul-color-high lr-color-high
  74.             hlight-color xpadding ypadding bevel ratio 1))))
  75.  
  76. (define (do-pupibutton text
  77.                size
  78.                font
  79.                ul-color
  80.                lr-color
  81.                text-color
  82.                xpadding
  83.                ypadding
  84.                bevel
  85.                ratio
  86.                pressed)
  87.  
  88.   (let* ((text-extents (gimp-text-get-extents-fontname text
  89.                                size
  90.                                PIXELS
  91.                                font))
  92.      (ascent (text-ascent text-extents))
  93.      (descent (text-descent text-extents))
  94.  
  95.      (height (+ (* 2 (+ ypadding bevel))
  96.             (+ ascent descent)))
  97.  
  98.      (radius (/ (* ratio height) 4))
  99.  
  100.      (width (+ (* 2 (+ radius xpadding))
  101.            bevel
  102.            (text-width text-extents)))
  103.  
  104.      (img (car (gimp-image-new width height RGB)))
  105.  
  106.      (bumpmap (car (gimp-layer-new img width height
  107.                        RGBA-IMAGE "Bumpmap" 100 NORMAL-MODE)))
  108.      (gradient (car (gimp-layer-new img width height
  109.                     RGBA-IMAGE "Button" 100 NORMAL-MODE))))
  110.  
  111.     (gimp-context-push)
  112.  
  113.     (gimp-image-undo-disable img)
  114.  
  115.     ; Create bumpmap layer
  116.     
  117.     (gimp-image-add-layer img bumpmap -1)
  118.     (gimp-selection-none img)
  119.     (gimp-context-set-background '(0 0 0))
  120.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  121.  
  122.     (round-select img (/ bevel 2) (/ bevel 2)
  123.           (- width bevel) (- height bevel) ratio)
  124.     (gimp-context-set-background '(255 255 255))
  125.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  126.  
  127.     (gimp-selection-none img)
  128.     (plug-in-gauss-rle 1 img bumpmap bevel 1 1)
  129.  
  130.     ; Create gradient layer
  131.  
  132.     (gimp-image-add-layer img gradient -1)
  133.     (gimp-edit-clear gradient)
  134.     (round-select img 0 0 width height ratio)
  135.     (gimp-context-set-foreground ul-color)
  136.     (gimp-context-set-background lr-color)
  137.  
  138.     (gimp-edit-blend gradient FG-BG-RGB-MODE NORMAL-MODE
  139.              GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
  140.              FALSE 0 0 TRUE
  141.              0 0 0 (- height 1))
  142.  
  143.     (gimp-selection-none img)
  144.  
  145.     (plug-in-bump-map 1 img gradient bumpmap
  146.               135 45 bevel 0 0 0 0 TRUE pressed 0)
  147.  
  148. ;     Create text layer
  149.  
  150.     (cond ((eqv? pressed 1) (set! bevel (+ bevel 1))))
  151.  
  152.     (gimp-context-set-foreground text-color)
  153.     (let ((textl (car (gimp-text-fontname
  154.                img -1 0 0 text 0 TRUE size PIXELS
  155.                font))))
  156.       (gimp-layer-set-offsets textl
  157.                   (+ xpadding radius bevel)
  158.                   (+ ypadding descent bevel)))
  159.  
  160. ;   Delete some fucked-up pixels.
  161.  
  162.     (gimp-selection-none img)
  163.     (round-select img 1 1 (- width 1) (- height 1) ratio)
  164.     (gimp-selection-invert img)
  165.     (gimp-edit-clear gradient)
  166.  
  167. ;     Done
  168.  
  169.     (gimp-image-remove-layer img bumpmap)
  170.     (gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
  171.  
  172.     (gimp-selection-none img)
  173.     (gimp-image-undo-enable img)
  174.     (gimp-display-new img)
  175.  
  176.     (gimp-context-pop)))
  177.  
  178. (script-fu-register "script-fu-round-button"
  179.             _"_Round Button..."
  180.             "Round button"
  181.             "Arturo Espinosa (stolen from quartic's beveled button)"
  182.             "Arturo Espinosa & Federico Mena Quintero"
  183.             "June 1998"
  184.             ""
  185.             SF-STRING     _"Text"                 "The GIMP"
  186.             SF-ADJUSTMENT _"Font size (pixels)"   '(16 2 100 1 1 0 1)
  187.             SF-FONT       _"Font"                 "Sans"
  188.             SF-COLOR      _"Upper color"          '(192 192 0)
  189.             SF-COLOR      _"Lower color"          '(128 108 0)
  190.             SF-COLOR      _"Text color"           '(0 0 0)
  191.             SF-COLOR      _"Upper color (active)" '(255 255 0)
  192.             SF-COLOR      _"Lower color (active)" '(128 108 0)
  193.             SF-COLOR      _"Text color (active)"  '(0 0 192)
  194.             SF-ADJUSTMENT _"Padding X"            '(4 0 100 1 10 0 1)
  195.             SF-ADJUSTMENT _"Padding Y"            '(4 0 100 1 10 0 1)
  196.             SF-ADJUSTMENT _"Bevel width"          '(2 0 100 1 10 0 1)
  197.             SF-ADJUSTMENT _"Round ratio"          '(1 0.05 20 0.05 1 2 1)
  198.             SF-TOGGLE     _"Not pressed"          TRUE
  199.             SF-TOGGLE     _"Not pressed (active)" TRUE
  200.             SF-TOGGLE     _"Pressed"              TRUE)
  201.  
  202. (script-fu-menu-register "script-fu-round-button"
  203.              _"<Toolbox>/Xtns/Script-Fu/Buttons")
  204.